<template>
  <div>
    <a-button-group>
      <a-button @click="upload">
        <template #icon>
          <UploadOutlined />
        </template>
        {{ t(uploadText) }}
      </a-button>
      <Download :url="downloadLink">
        {{ t('下载模板') }}
      </Download>
    </a-button-group>
    <UploadCallback
      v-if="result"
      :suc="result.suc"
      :sum="result.sum"
      :tips="result.tips"
      v-model:visible="open"
      :unknown="result.unknown"
    />
  </div>
</template>

<script setup lang="ts">
import {
  uploadTemplate,
  type UploadGroupParams,
  type UploadResult,
} from '@/api/modules/utils/files';
import { message } from 'ant-design-vue';
const open = ref(false);
const { t } = useI18n();
const props = defineProps<UploadGroupParams>();

const result = ref<UploadResult>();
const upload = async () => {
  const { data } = await uploadTemplate({
    link: props.uploadLink,
    type: props.uploadType,
  });
  message.info(data.msg);
  if (props.showResult) {
    result.value = data.data;
    open.value = true;
  }
};
</script>

<style lang="scss" scoped></style>
